<%@page import="board.BoardVo"%>
<%@page import="java.util.Vector"%>
<%@page import="board.Board"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<link rel="stylesheet" type="text/css" href='./board/board.css'>
<script src='./board/board.js'></script>

</head>
<body>
<jsp:useBean id="boardVo" class="board.BoardVo"/>
<jsp:setProperty property="*" name="boardVo"/>
<%

//검색어 세션처리
if(request.getMethod().equals("POST")){
	session.setAttribute("find",boardVo.getFind());
}else{
	if((String)session.getAttribute("find") !=null){
		boardVo.setFind((String)session.getAttribute("find"));
	}	
}
//페이지 정보 유지
if(request.getParameter("nowPage")==null){
	if(session.getAttribute("nowPage") != null){
		boardVo.setNowPage((Integer)session.getAttribute("nowPage"));
	}
}else{
	session.setAttribute("nowPage", boardVo.getNowPage());
}


String mid = (String)session.getAttribute("mid");
String part = (String)session.getAttribute("part"); 
boardVo.setPart(part);

if(mid==null) mid = "notUser";

Board board = new Board();
board.setVo(boardVo);
board.setNowPage(boardVo.getNowPage());

Vector<BoardVo> v = board.list();


%>
<!-- title -->
<div id='bb_title'><%=part%></div><br/>
<!-- end title -->
<div id='brd_out'>



<div id='brd_line'>
	<div id='brd_input'>
		<%if("공지".equals(part)){ 
			if("admin".equals(mid)){%>
				<input type='button' id='brd_btnInput' value='글쓰기' onclick="brd_input()">
			<%}else{ %>
				<div style="font-family: Hanna">관리자만 글을 쓸수 있습니다.</div>
			<%} %>
		<%}else if("익명게시판".equals(part)){ %>
			<input type='button' id='brd_btnInput' value='글쓰기' onclick="brd_input()">
		<%}else{
			if(!"notUser".equals(mid)){%>
				<input type='button' id='brd_btnInput' value='글쓰기' onclick="brd_input()">
			<%}else{ %>
				<div style="font-family: Hanna">로그인 후 글을 쓸수 있습니다.</div>
			<%} %>
		<%} %>
	</div>
</div>

<div id='brd_line'>
	<div id='brd_title'>
		<div id='brd_serial'>글 번호</div>
		<div id='brd_subject'>제 목</div>
		<div id='brd_mid'>작성자</div>
		<div id='brd_mdate'>작성일</div>
		<div id='brd_hit'>조회</div>
	</div>
</div>
<%Board re = new Board();
for(int i=0; i<v.size(); i++){
	BoardVo bv = v.get(i); 
	String str = bv.getDeep();//DEEP컬럼에서 "-"의 개수만큼 g++시켜 앞에 공백을 넣음
				int g = 0;
				for(int j=0; j<str.length(); j++){
					if(str.charAt(j) != '-')continue;
					g++;
				}
				String gab ="";
				for(int k = 0; k<g; k++){
					gab += "　";
				}
				
				%>
	
	<div id='brd_line'>
	<div id='brd_substance'>
		<%if(g>0){%>
			<div id='brd_serial'>　</div>
		<%}else{%>
			<div id='brd_serial'><%=bv.getSerial()%></div>
		<%}%>
		<div id='brd_subject'>
			<a href="index.jsp?inc_contents=./board/view.jsp&serial=<%=bv.getSerial()%>">
				<%=gab%><%=bv.getSubject()%>(<%=re.commentGet(bv.getSerial())%>)
			</a>
		</div>
		<div id='brd_mid'><%=bv.getMid()%></div>
		<div id='brd_mdate'><%=bv.getMdate()%></div>
		<div id='brd_hit'><%=bv.getHit()%></div>
	</div>
</div>
	
<%} re.endConn();%>

<!--  -->
<div id='brd_line'><!-- 페이지 분리 영역 -->
	<%if(board.getNowBlock()>1){ %>
		<label><a onclick='goPage(1)'>처음</a></label>
		<label><a onclick='goPage(<%=board.getStartPage()-1%>)'>이전</a></label>
	
	<%}else{ %>
		<label><a>처음</a></label>
		<label><a>이전</a></label>
	<%} %>
	[
	<%for(int p=board.getStartPage(); p<=board.getEndPage(); p++){
		if(session.getAttribute("nowPage")!=null){%>
		<label><a onclick='goPage(<%=p%>)'>
			
			<%if((Integer)session.getAttribute("nowPage")==p){ %>
				<b>(<%=p%>)</b>
			<%}else{ %>
				(<%=p%>)
			<%} 
			}%>
		</a></label>
		
	<%}%>
	]
	<%if(board.getNowBlock()<board.getTotBlock()){ %>
		<label><a onclick='goPage(<%=board.getEndPage()+1%>)'>이후</a></label>
		<label><a onclick='goPage(<%=board.getTotPage()%>)'>마지막</a></label>
	<%}else{ %>
	<label><a>이후</a></label>
	<label><a>마지막</a></label>
<%} %>
</div>
<div id='brd_line'>
	<form id='brd_find' name="board_frm" method="post">
		<input type='search' name='find' id='find' value="<%=boardVo.getFind()%>">
		<input type='button' id='brd_btnFind' value='검색'>
		<input type='hidden' name='nowPage' value="<%=board.getNowPage()%>">
	</form>
</div>
<%-- <div id='brd_line' style="height:400px;">
	<ul>
		<li>전체 검색 건수: <%=board.getTotSize()%>
		<li>페이지수: <%=board.getTotPage()%>
		<li>블럭수: <%=board.getTotBlock()%>
		<li>현재블럭: <%=board.getNowBlock()%>
		<li>시작페이지: <%=board.getStartPage()%>
		<li>끝페이지: <%=board.getEndPage()%>
		<li>시작번호: <%=board.getStartNo()%>
		<li>끝번호: <%=board.getEndNo()%>
	</ul>
</div> --%>
</div>

</body>
</html>